import time

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
driver.maximize_window()
# driver.set_window_size(1600,1024)
driver.get('https://www.baidu.com/')
# driver.set_window_size()

time.sleep(2)
# ActionChains(driver).move_to_element(driver.find_element_by_id('s-usersetting-top')).perform()
# attr = driver.find_element_by_id('kw').get_attribute('autocomplete')
# print(attr)
# driver.refresh()
# driver.get('http://beike.zxxk.com/index.html#/')
#
# time.sleep(2)
# driver.back()

# 根据id定位
driver.find_element_by_id("kw").send_keys("python selenium")
# driver.find_element_by_id("kw").send_keys(Keys.CONTROL, 'a')
driver.find_element_by_id('kw').send_keys(Keys.ENTER)
time.sleep(3)
title = driver.title
print(title)
print(driver.current_url)
time.sleep(3)

# 根据name定位
# driver.find_element_by_name("wd").send_keys("selenium")

# 根据class 定位
# driver.find_element_by_class_name('s_ipt').send_keys("selenium")
# 根据链接 tag
# eles = driver.find_element_by_tag_name('input')
# print(eles)

# 根据链接 link
# driver.find_element_by_link_text('新闻').click()

# 根据链接部分文本
# driver.find_element_by_partial_link_text("高考").click()
# attribute = driver.find_elements
# print(attribute)
# eles = driver.find_elements_by_tag_name("input")  # 17个
# print(eles, len(eles))

# driver.find_element_by_xpath('//input[@autocomplete="off"]').send_keys('python')
# driver.find_element_by_css_selector('#kw').send_keys('python')
# sleep(5)

driver.quit()

#上传按钮
# 通过id
# 通过name
# 通过xpath、css